/*
 * @Author: WHAlex
 * @Date: 2025-01-21 11:28:32
 *
 * Copyright (c) 2025 by atguigu, All Rights Reserved.
 */
#include "Inf_WS2812.h"

// 灯带操作句柄
static led_strip_handle_t led_strip;

/**
 * @description: 配置灯带参数
 * @return {*}
 */
static void configure_led(void)
{
    // LED strip general initialization, according to your led board design
    led_strip_config_t strip_config = {
        .strip_gpio_num = LED_STRIP_GPIO_PIN,                        // The GPIO that connected to the LED strip's data line
        .max_leds = LED_STRIP_LED_COUNT,                             // The number of LEDs in the strip,
        .led_model = LED_MODEL_WS2812,                               // LED strip model
        .color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB, // The color order of the strip: GRB
        .flags = {
            .invert_out = false, // don't invert the output signal
        }};

    // LED strip backend configuration: RMT
    led_strip_rmt_config_t rmt_config = {
        .clk_src = RMT_CLK_SRC_DEFAULT,        // different clock source can lead to different power consumption
        .resolution_hz = LED_STRIP_RMT_RES_HZ, // RMT counter clock frequency
        .mem_block_symbols = 64,               // the memory size of each RMT channel, in words (4 bytes)
        .flags = {
            .with_dma = false, // DMA feature is available on chips like ESP32-S3/P4
        }};

    (led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
}
/**
 * @description: WS2812初始化
 * @return {*}
 */
void Inf_WS2812_Init(void)
{
    // 创建灯带操作句柄
    configure_led();
}

/**
 * @description: 亮灯
 * @return {*}
 */
void Inf_WS2812_LedOn(void)
{
    // 配置两个灯的颜色数据
    led_strip_set_pixel(led_strip, 0, 30, 30, 30);
    led_strip_set_pixel(led_strip, 1, 30, 30, 30);

    // 发送灯带颜色数据
    led_strip_refresh(led_strip);
}

/**
 * @description:灭灯
 * @return {*}
 */
void Inf_WS2812_LedOff(void)
{
    led_strip_clear(led_strip);
}